        solvedfs(Node,Solution) :- 
            df([],Node,Solution).

        df(Path,Node,[Node|Path]) :- 
            goal(Node).
        df(Path,Node,Sol) :- 
            s(Node,Node1),
            not member(Node1,Path), % No Cycles!
            df([Node|Path],Node1,Sol).

        solvedfs(Node,Solution) :- 
            bf([[Node]],Solution).

        bf([[Node|Path]|_],[Node|Path]) :-
            goal(Node).
        bf([[N|Path]|Paths],Solution) :-
            bagof([M,N|Path],
                  (s(N,M),not member(M,[N|Path])),
                  Newpaths), % Newpaths = acyclic extensions of [N|Path]
            append(Paths,Newpaths,Paths1), !,
            bf(Paths1,Solution);
            bf(Paths,Solution).   % Case that N has no successors.

        goal([_,_,_,_,_,_,_,_]).

        s(Queens,[Queen|Queens]) :-
            member(Queen,[1,2,3,4,5,6,7,8]),
	    not member(Queen, Queens),
            safe([Queen|Queens]).

        safe([]).
        safe([Queen|Others]) :-
            safe(Others),
            noattack(Queen,Others,1).

        noattack(_,[],_).
        noattack(Y,[Y1|Ylist],Xdist) :- 
            Y1 - Y =\= Xdist,
            Y - Y1 =\= Xdist, 
            Dist1 is Xdist + 1,
            noattack(Y, Ylist, Dist1).
